// 步骤
// 1.导入自定义好的 request
import request from '../utils/request'
// import store from '@/store'
// 2.定义接口函数
// 首页-获取用户选择的频道
const getUserChannelListApi = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/channels'
    // headers: {
    //   // 请求头：登陆接到的token值, 前面需要拼接Bearer空格
    //   Authorization: `Bearer ${store.state.token}`
    // }
  })
}

// 首页-获取文章列表
const getArticleListAPI = ({
  channelId,
  timestamp = Date.now() + ''
}) => {
  return request({
    method: 'GET',
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp
    }
  })
}

// 首页-文章-不感兴趣
const articleDislikeAPI = ({ artId }) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/dislikes',
    // headers: {
    //   // Authorization: 'Bearer ' + store.state.token
    //   Authorization: `Bearer ${store.state.token}`
    // },
    data: {
      target: artId
    }
  })
}

// 首页-文章-举报
const articleReportsAPI = ({ artId, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`
    // },
    data: {
      target: artId,
      type: type,
      remark: type === '0' ? remark : remark || null
    }
  })
}

// 首页-获取所有频道
const getAllChannelListAPI = () => {
  return request({
    method: 'GET',
    url: '/v1_0/channels'
  })
}

// 首页 - 修改(更新)用户选择的频道
const updateUserChannelListAPI = ({ channels }) => {
  return request({
    method: 'PUT',
    url: '/v1_0/user/channels',
    data: {
      channels
    }
  })
}

// 3.按需导出
export {
  getUserChannelListApi,
  getArticleListAPI,
  articleDislikeAPI,
  articleReportsAPI,
  getAllChannelListAPI,
  updateUserChannelListAPI
}
